public class MostElements {
    public static int most(int[] arr) {
        int n = 0;
        int num = arr[0];
        for(int i = 0;i < arr.length;i++) {
            if(arr[i] == num) {
                n++;
            } else {
                n--;
            }
            if(n<0)  {
                num = arr[i];
            }
        }
        return num;
    }
    public static void main(String[] args) {
        int[] arr = {1,2,3,4,5,6,2,2,2,2};
        System.out.println(most(arr));
    }
}
